﻿using System.Data;
using Microsoft.Data.SqlClient;

namespace DaoService;

public class ConnectionUtil
{
    // MySQL 连接信息
    private const string Server = "127.0.0.1";
    private const int Port = 3307;
    private static string Database = "logs";
    private const string UserId = "root";
    private const string Password = "123456";
    private const string BizDatabase = "packagingrobot";
    public static string ConnectionString => 
        $"Server={Server};Port={Port};Database={Database};Uid={UserId};Pwd={Password};";
    public static string BizConnectionString => 
        $"Server={Server};Port={Port};Database={BizDatabase};Uid={UserId};Pwd={Password};";
    public static SqlConnection getConnection()
    {
        return new SqlConnection(ConnectionString);
    }
    
    // 创建连接的工厂方法
    public static IDbConnection CreateMySqlConnection(string database)
    {
        Database = database;
        // 根据需要选择不同的数据库连接实现
        return new MySql.Data.MySqlClient.MySqlConnection(ConnectionString);
        // 如果使用 SQL Server，则改为：
        // return new System.Data.SqlClient.SqlConnection(_connectionString);
    }
    
}